$(function() {
    var myApp = [{
        imgName: "icon_bgoa",
        name: "办公OA",
        id: "0",
        permission: true //有权限否
    }];
    var appList = [{
        imgName: "icon_jygl",
        name: "监狱管理",
        id: "1",
        permission: true
    }, {
        imgName: "icon_jdgl",
        name: "戒毒管理",
        id: "2",
        permission: true
    }, {
        imgName: "icon_sqjz",
        name: "矫正社区",
        id: "3",
        permission: true
    }, {
        imgName: "icon_lsgl",
        name: "律师管理",
        id: "4",
        permission: true
    }, {
        imgName: "icon_jcflfw",
        name: "基层法律服务",
        id: "5",
        permission: true
    }, {
        imgName: "icon_gzgl",
        name: "公证管理",
        id: "6",
        permission: false
    }, {
        imgName: "icon_flyz",
        name: "法律援助",
        id: "7",
        permission: true
    }, {
        imgName: "icon_jcgz",
        name: "基层工作",
        id: "9",
        permission: true
    }, {
        imgName: "icon_sfks",
        name: "司法考试",
        id: "10",
        permission: true
    }, {
        imgName: "icon_sfjd",
        name: "司法鉴定",
        id: "11",
        permission: true
    }, {
        imgName: "icon_wwdz",
        name: "外网地址",
        id: "12",
        permission: false
    }, {
        imgName: "icon_12348",
        name: "12348浙江法网",
        id: "13",
        permission: true
    }, {
        imgName: "icon_sjywgl",
        name: "审计业务管理",
        id: "14",
        permission: true
    }, {
        imgName: "icon_jczbgl",
        name: "计财装备管理",
        id: "15",
        permission: true
    }, {
        imgName: "icon_jwrsgl",
        name: "警务人事管理",
        id: "16",
        permission: true
    }, {
        imgName: "icon_jszy",
        name: "数据资源",
        id: "17",
        permission: true
    }, {
        imgName: "icon_sjbz",
        name: "数据标准",
        id: "18",
        permission: true
    }, {
        imgName: "icon_alk",
        name: "案例库",
        id: "19",
        permission: true
    }, {
        imgName: "icon_xtgl",
        name: "系统管理",
        id: "20",
        permission: true
    }, {
        imgName: "icon_yhtx",
        name: "用户体系",
        id: "21",
        permission: true
    }, {
        imgName: "icon_zzjy",
        name: "组织教育",
        id: "22",
        permission: true
    }, {
        imgName: "icon_zfjg",
        name: "执法监管",
        id: "23",
        permission: true
    }, {
        imgName: "icon_xmgl",
        name: "项目管理",
        id: "24",
        permission: true
    }, {
        imgName: "icon_bzxt",
        name: "被装系统",
        id: "25",
        permission: true
    }]
    layui.use('laytpl', function() {
        var laytpl = layui.laytpl;
        renderHtmlList()

        function setClick() {
            $('#my-app-list .app-item .after-icon').on('click', function() {
                var $id = parseInt($(this).data('id')); //获取下标
                var a = myApp.splice($id, 1); //根据下标删除数组中
                appList.push(a[0]) //放回所有列表中
                // 重新渲染
                renderHtmlList()
            })
            $('#view-all-app .app-item .after-icon').on('click', function() {
                var $id = parseInt($(this).data('id')); //获取下标
                var a = appList.splice($id, 1); //根据下标删除所有列表数组中的一项
                myApp.push(a[0]) //添加进myapp
                // 重新渲染
                renderHtmlList()
            })
        }

        function renderHtmlList() {
            renderAllApp()
            renderMyapp()
            setClick() //添加点击事件
        }

        function renderAllApp() {
            var getTpl = mhyApp.innerHTML;
            var view = document.getElementById('view-all-app');
            laytpl(getTpl).render(appList, function(html) {
                view.innerHTML = html;
            });

        }

        function renderMyapp() {
            var getTpl = mhyApp.innerHTML;
            var view = document.getElementById('my-app-list');
            laytpl(getTpl).render(myApp, function(html) {
                view.innerHTML = html;
            });


        }

    })
})